{include file="public/header" type="layui-layout-body pear-admin"/}
<script>
    if (window != top) {
        top.location.href = location.href;
    }
</script>
<style type="text/css" >
    .layui-nav.layui-nav-tree {
    width: 230px;
}
</style>
<!-- 布 局 框 架 -->
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <!-- 顶 部 左 侧 功 能 -->
        <ul class="layui-nav layui-layout-left">
            <li class="collaspe layui-nav-item"><a href="#" class="layui-icon layui-icon-shrink-right"></a></li>
            <li class="refresh layui-nav-item"><a href="#" class="layui-icon layui-icon-refresh-1" loading=600></a></li>
        </ul>
        <!-- 顶 部 右 侧 菜 单 -->
        <div id="control" class="layui-layout-control"></div>
        <ul class="layui-nav layui-layout-right" lay-filter="layui_nav_right">
            <li class="layui-nav-item layui-hide-xs"><a href="#"
                                                        class="fullScreen layui-icon layui-icon-screen-full"></a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="/" target="_blank">网站前台</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="javascript:void(0);" class="detection">数据检测</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="javascript:void(0);" class="update">检查更新</a></li>
            <li class="layui-nav-item user">
                <!-- 头 像 -->
                <a href="javascript:;">
                    <img src="/static/admin/images/avatar.jpg" class="layui-nav-img">
                    {$nickname}
                </a>
                <!-- 功 能 菜 单 -->
                <dl class="layui-nav-child">
                    <dd>
                        <a href="javascript:void(0);" class="password">
                            修改密码
                        </a>
                    </dd>
                    <dd>
                        <a href="javascript:void(0);" class="cache">
                            清理缓存
                        </a>
                    </dd>
                    <dd>
                        <a href="javascript:void(0);" class="logout">
                            退出登录
                        </a>
                    </dd>
                </dl>
            </li>
            <!-- 主 题 配 置 -->
            <li class="layui-nav-item setting"><a href="#" class="layui-icon layui-icon-more-vertical"></a></li>
        </ul>
    </div>
    <!-- 侧 边 区 域 -->
    <div class="layui-side layui-bg-black">
        <!-- 顶 部 图 标 -->
        <div class="layui-logo">
            <!-- 图 表 -->
            <!--<img class="logo"></img>-->
            <!-- 标 题 -->
            <span class="title"></span>
        </div>
        <!-- 侧 边 菜 单 -->
        <div class="layui-side-scroll">
            <div id="sideMenu"></div>
        </div>
    </div>
    <!-- 视 图 页 面 -->
    <div class="layui-body" style="background-color: whitesmoke;">
         <!-- 内 容 页 面 -->
         {if !$vars['licence']}
         <div class="pear-container">
             <div class="layui-card" id="licence_n" style="margin-bottom: -15px;">
                 <div class="layui-card-header">
                     <h2 style="color: red">您的应用还未授权</h2>
                 </div>
                 <div class="layui-card-body">
                     商业使用请前往：<a target="_blank" href="https://www.yfxw.cn" style="color: #0d6efd">https://www.yfxw.cn</a>
                     购买。如果你已有激活码请
                     <button class="pear-btn pear-btn-sm pear-btn-primary" onclick="drawer_licence()"> 立即激活</button>
                 </div>
             </div>
 
             <div class="mSlider-main ms-ivopxh"
                  style="display: none; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 9999999;">
                 <div class="mSlider-inner"
                      style="position: absolute; top: 0px; left: 0px; width: 100%; height: 30%; background-color: rgb(255, 255, 255); transform: translate3d(0px, -100%, 0px); transition: all 0.2s ease-out 0s; z-index: 10000000;">
                     <div class="layer-top" style="display: block;">
                         <div class="layui-card">
                             <div class="layui-card-header">
                                 <h3>授权设置</h3>
                             </div>
                             <div class="layui-card-body">
                                <div class="layui-tab layui-tab-brief" lay-filter="authActivate">
                                    <ul class="layui-tab-title">
                                        <li>常规激活</li>
                                        <li class="layui-this">密钥激活</li>
                                    </ul>
                                    <div class="layui-tab-content">
                                        <div class="layui-tab-item">
                                            <div class="layui-input-block" style="min-height: 80px;">
                                                <button class="pear-btn pear-btn-primary" onclick="submit('regular')">立即激活</button>
                                            </div>
                                        </div>
                                        <div class="layui-tab-item layui-show">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label" style="width:60px;padding: 9px 0;">激活密钥</label>
                                                <div class="layui-input-block" style="margin-left: 0;">
                                                    <input autocomplete="off" class="layui-input" 
                                                           name="activation_key" 
                                                           placeholder="请输入激活密钥" 
                                                           id="activation_key" 
                                                           value="" 
                                                           type="text"/>
                                                </div>
                                            </div>
                                            <div class="layui-input-block" style="min-height: 80px;">
                                                <button class="pear-btn pear-btn-primary" onclick="submit('key')">密钥激活</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                         </div>
                         <div class="layui-card">
                             <div class="layui-card-header">
                                 <h3>为什么购买正版？</h3>
                             </div>
                             <div class="layui-card-body">
                                 1. 正版授权，避免侵权风险，保护您的合法权益；<br/>
                                 2. 及时更新和升级，获得系统最新的功能和优化；<br/>
                                 3. 优先获得我们的技术支持和服务，快速解决您在使用过程中遇到的问题。<br/>
                             </div>
                         </div>
                     </div>
                 </div>
                 <div class="mSlider-mask"
                      style="width: 100%; height: 100%; opacity: 0; background-color: black; z-index: 9999998; backface-visibility: hidden;"></div>
             </div>
         </div>
 
         <script>
 
             function drawer_licence() {
                 layui.use(['drawer'], function () {
                     var drawer = layui.drawer;
                     drawer.open({
                         direction: "right",
                         dom: ".layer-top",
                         distance: "350px"
                     });
                 })
             }
 
             function submit(type) {
            layui.use(['form', 'jquery', 'popup'], function () {
                let popup = layui.popup;
                let $ = layui.jquery;
                let auth_id = "";
                let auth_secret = "";

                if (type === 'key') {
                    auth_secret = $("#activation_key").val();
                    if (!auth_secret) {
                        popup.warning('请输入激活密钥');
                        return false;
                    }
                }

                $.ajax({
                    url: '{$Request.root}/auth',
                    data: JSON.stringify({
                        'type': type,
                        'auth_secret': auth_secret,
                    }),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (res) {
                        if (res) {
                            layer.msg('激活成功', {
                                icon: 1,
                                time: 1000,
                            }, function () {
                                location.reload();
                            })

                            return false;
                        } else {
                            layer.msg('激活失败', {
                                icon: 5,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }
         </script>
        {/if}
 
         <script>
             if (window.location.href.indexOf('/index') === -1 && window.location.href.indexOf('/admin.php/update') === -1) {
             	var t = document.getElementById('licence_n');
             	t.style.display = 'none';
             }
         </script>
 
        <div id="content"></div>
    </div>
</div>
<!-- 遮 盖 层 -->
<div class="pear-cover"></div>
<!-- 移 动 端 便 捷 操 作 -->
<div class="pear-collasped-pe collaspe" style="background-color:unset !important;
"><a href="#" class="layui-icon layui-icon-shrink-right"></a></div>
<!-- 加 载 动 画-->
<div class="loader-main">
    <div class="loader"></div>
</div>
<!-- 依 赖 脚 本 -->
{include file="public/footer"/}
<!-- 框 架 初 始 化 -->
<script>
    layui.use(['admin', 'jquery', 'layer', 'element', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var layelem = layui.element;
        var admin = layui.admin;
        let form = layui.form;


        // 框 架 初 始 化
        admin.render({
            "logo": {
                "title": "YPAY Admin",

            },
            "menu": {
                "data": "{$Request.root}/index/menu",
                "accordion": true,
                "control": false,
                "select": "0"
            },
            "tab": {
                "muiltTab": true,
                "keepState": true,
                "session": true,
                "tabMax": 30,
                "index": {
                    "id": "0",
                    "href": "{$Request.root}/index/home",
                    "title": "首页"
                }
            },
            "theme": {
                "defaultColor": "2",
                "defaultMenu": "dark-theme",
                "defaultHeader": "light-theme",
                "allowCustom": true,
                "banner": false
            },
            "colors": [{
                "id": "1",
                "color": "#2d8cf0",
                "second": "#ecf5ff"
            },
                {
                    "id": "2",
                    "color": "#36b368",
                    "second": "#f0f9eb"
                },
                {
                    "id": "3",
                    "color": "#f6ad55",
                    "second": "#fdf6ec"
                }, {
                    "id": "4",
                    "color": "#f56c6c",
                    "second": "#fef0f0"
                }, {
                    "id": "5",
                    "color": "#3963bc",
                    "second": "#ecf5ff"
                }
            ],
            "other": {
                "keepLoad": 100
            },
            "header": {
                message: false
            }
        });


        layelem.on('nav(layui_nav_right)', function (elem) {
            if ($(elem).hasClass('logout')) {
                layer.confirm('确定退出登录吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: '{$Request.root}/login/logout',
                        type: "POST",
                        dataType: "json",
                        success: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {
                                    icon: 1
                                });
                                setTimeout(function () {
                                    location.href = '{$Request.root}/login/index';
                                }, 333)
                            }
                        }
                    });
                });
            } else if ($(elem).hasClass('password')) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改密码',
                    shade: 0.1,
                    area: ['300px', '300px'],
                    content: '{$Request.root}/index/pass'
                });
            } else if ($(elem).hasClass('cache')) {
                $.post('{$Request.root}/index/cache',
                    function (data) {
                        layer.msg(data.msg, {time: 1500});
                        location.reload()
                    });

            } else if ($(elem).hasClass('update')) {
                $.post('{$Request.root}/Update/checkver',
                    function (data) {

                        if (data.code == 202) {
                            layer.alert(data.msg);
                            return false;
                        }

                        if (data.code == 201) {
                            layer.open({
                                type: 1,
                                title: 'YPAY系统在线更新',
                                //   area: '560px',
                                shadeClose: true,
                                skin: 'layui-col-md4',
                                closeBtn: 1,
                                content: '<div class="setchmod bt-form">\
                                    <div class="update_title"><i class="layui-layer-ico layui-layer-ico1" style="position: absolute;top: 16px;left: 15px;_left: -40px;width: 30px;height: 30px;"></i><span>恭喜您，当前已经是最新版本</span></div>\
                                    <div class="update_version">当前版本：<a href="javascript:void(0);"  class="btlink" title="查看当前版本日志">' + data.data.vername + '</div>\
                                    <div class="update_conter">\
                                        <div class="update_tips">' + '最新版本&nbsp;：' + data.data.vername + '&nbsp;&nbsp;&nbsp;更新时间&nbsp;&nbsp;：' + data.data.vertime + '&nbsp;&nbsp;&nbsp;\
                                        ' + '\
                                        ' + '\
                                        </div>\
                                    </div>\
                                    </div>\
                                <style>\
                                    .setchmod{padding-bottom:50px;}\
                                    .update_title{overflow: hidden;position: relative;vertical-align: middle;margin-top: 10px;}\
                                    .update_title .layui-layer-ico{display: block;left: 60px !important;top: 1px !important;}\
                                    .update_title span{display: inline-block;color: #333;height: 30px;margin-left: 105px;margin-top: 3px;font-size: 20px;}\
                                    .update_conter{background: #f9f9f9;border-radius: 4px;padding: 20px;margin: 15px 37px;margin-top: 15px;}\
                                    .update_version{font-size: 12px;margin:15px 0 10px 100px}\
                                    .update_logs{margin-bottom:10px;border-bottom:1px solid #ececec;padding-bottom:10px;}\
                                    .update_tips{font-size: 13px;color: #666;font-weight: 600;}\
                                    .update_tips span{padding-top: 5px;display: block;font-weight: 500;}\
                                </style>'
                            });
                            return;
                        } else {

                            var time = data.data.vertime;
                            var version = data.data.version;
                            var updateMsg = data.data.updateMsg;
                            layer.open({
                                type: 1,
                                title: 'YPAY系统在线更新',
                                //   area: '560px',
                                shadeClose: true,
                                skin: 'layui-col-md4',
                                closeBtn: 1,
                                content: '<div class="setchmod bt-form" style="padding-bottom:50px;">\
                                        <div class="update_title"><i class="layui-layer-ico layui-layer-ico0" style="position: absolute;top: 16px;left: 15px;_left: -40px;width: 30px;height: 30px;"></i><span>有新的系统版本更新，是否更新？</span></div>\
                                        <div class="update_conter" style="max-height: 400px;overflow: auto;">\
                                            <div class="update_version">最新版本：<a href="/"  class="btlink" title="查看版本更新日志">YPAY ' + version + '</a>&nbsp;&nbsp;更新日期：' + time + '</div>\
                                            <div class="update_logs">' + updateMsg + '</div>\
                                        </div>\
                                         <div class="bottom">\
                                            <div class="button-container">\
                                            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">' + "取消更新" + '</button>\
                                            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="to_update" >' + "立即更新" + '</button>\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <style>\
                                        .update_title{overflow: hidden;position: relative;vertical-align: middle;margin-top: 10px;}.update_title .layui-layer-ico{display: block;left: 60px !important;top: 1px !important;}.update_title span{display: inline-block;color: #333;height: 30px;margin-left: 105px;margin-top: 3px;font-size: 20px;}.update_conter{background: #f9f9f9;border-radius: 4px;padding: 20px;margin: 15px 37px;margin-top: 15px;}.update_version{font-size: 13.5px; margin-bottom: 10px;font-weight: 600;}.update_logs{margin-bottom:10px;}.update_tips{font-size: 13px;color:#666;}.update_conter span{display: block;font-size:13px;color:#666}\
                                    </style>'
                            });
                            return;
                        }


                    });

            }else if ($(elem).hasClass('detection')) {
                $.post('{$Request.root}/index/detection',
                    function (data) {
                        layer.msg(data.msg, {time: 1500});
                    });

            }

        });

        form.on('submit(to_update)', function () {
            layer.closeAll();
            //layer.alert('cs');
            $.post('{$Request.root}/update/update_ver',
                function (data) {
                    layer.alert(data.msg);
                    return false;
                });

        });

    })
</script>
</body>
</html>
